<?php

namespace app\common\model\User;

use think\Model;

class Star extends Model
{
    protected $name = 'business_star';

    //开启自动写入时间戳字段
    protected $autoWriteTimestamp = 'int';

    //定义时间戳字段名
    protected $createTime = 'createtime';

    //关闭自动更新时间戳
    protected $updateTime = false;

    //开启过滤
    protected $field = true;

    //设置获取器，需要进行操作的字段
    protected $append = [
        'cleatetime_text', //创建时间
    ];

    //创建时间
    public function getCleatetimeTextAttr($value, $data)
    {
        $createtime = isset($data['createtime']) ? $data['createtime'] : '';
        if ($createtime) {
            return date('Y-m-d H:i', $createtime);
        } else {
            return '';
        }
    }

    //连表
    public function user()
    {
        return $this->belongsTo('app\common\model\User\User', 'userid', 'id', [], 'LEFT')->setEagerlyType(0);
    }

    public function posts()
    {
        return $this->belongsTo('app\common\model\Posts\Posts', 'postid', 'id', [], 'LEFT')->setEagerlyType(0);
    }


}
